package controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import pojo.SysUser;
import service.SysUserService;
import utils.Constants;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @Resource
    SysUserService sysUserService;

    @RequestMapping("/toLogin")
    public String toLogin(){
        return "login";
    }

    @RequestMapping("/login")
    public String doLogin(String account, String password, HttpSession session){
        SysUser sysUser = sysUserService.login(account, password);
        if(sysUser!=null){
            session.setAttribute(Constants.USER_SESSION,sysUser);
            return "frame";
        }
        return "login";
    }

    @RequestMapping("/logout")
    public String logout(HttpSession session){
        session.removeAttribute(Constants.USER_SESSION);
        return "login";
    }


}
